Kokaの例: Generator
code:koka(js)
effect yield<a>
fun yield(x: a): ()
fun traverse(xs: list<a>): yield<a> ()
match xs
Cons(x,xx) -> { yield(x); traverse(xx) }
Nil -> ()
handle部分
code:koka(js)
fun main(): console ()
with fun yield(i: int)
println("yielded " ++ i.show)
with fun ..を使うことで自然にresumeしてる
code:result
yielded 1
yielded 2
yielded 3
yielded 4
yielded 5
参考
恐らく古いverionのKokaで書かれてる
@yurihaia: kinda cool research language named Koka the concepts (especially effects & effect handlers) allows making your own generators, async-await, and stuff like that all
https://pbs.twimg.com/media/E0SB801XEAAZn1b.pnghttps://pbs.twimg.com/media/E0SB9-zXMAUlYdF.png